package com.yxjx.duoxue.course;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import com.tencent.stat.StatService;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.yxjx.duoxue.BaseActionBarActivity;
import com.yxjx.duoxue.R;
import com.yxjx.duoxue.ReportErrorDialogHelper;
import com.yxjx.duoxue.Yx;
import com.yxjx.duoxue.YxSegment;
import com.yxjx.duoxue.YxTearchersHSVHelper;
import com.yxjx.duoxue.R.id;
import com.yxjx.duoxue.YxTearchersHSVHelper.HsvAdapter;
import com.yxjx.duoxue.activities.RichTextHelper;
import com.yxjx.duoxue.comment.AllThumbnailsView;
import com.yxjx.duoxue.comment.CommentFunctionView;
import com.yxjx.duoxue.comment.DetailedCommentActivity;
import com.yxjx.duoxue.customview.OutScrollView;
import com.yxjx.duoxue.customview.YxDetailedInfoView1;
import com.yxjx.duoxue.customview.YxFoldableListView;
import com.yxjx.duoxue.customview.YxTabHost;
import com.yxjx.duoxue.customview.YxDetailedInfoView1.YxListAdapter1;
import com.yxjx.duoxue.customview.YxFoldableListView.FoldableAdapter;
import com.yxjx.duoxue.customview.YxTabHost.Callback;
import com.yxjx.duoxue.datamodel.DMAllComments;
import com.yxjx.duoxue.datamodel.DMComment;
import com.yxjx.duoxue.datamodel.DMCommentLevelAvg;
import com.yxjx.duoxue.datamodel.DMTeacher;
import com.yxjx.duoxue.datamodel.course.DMCourse;
import com.yxjx.duoxue.datamodel.school.DMSchool;
import com.yxjx.duoxue.datamodel.school.SchoolDetailBrandDTS;
import com.yxjx.duoxue.datamodel.school.SchoolDetailEnvironmentDTS;
import com.yxjx.duoxue.datamodel.school.SchoolDetailServiceDTS;
import com.yxjx.duoxue.datamodel.school.SchoolDetailTeacherDTS;
import com.yxjx.duoxue.mta.stat.StatHelper;
import com.yxjx.duoxue.network.NwUtils;
import com.yxjx.duoxue.network.UserLoginResponse;
import com.yxjx.duoxue.utils.UIHelper;
import com.yxjx.duoxue.utils.Utils;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.app.ActionBar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.ScrollView;
import android.widget.TextView;

public class SchoolIntroductionActivity extends BaseActionBarActivity {

	public static final int REQ_CODE_LOGIN_FOR_ADD_COMMENT = 1;
	// flag used to determain the dialog dismiss time point.
	private boolean mSchoolReady = false;
	private boolean mTeacherReady = false;
	private boolean mCoursesReady = false;

	private DMSchool mCurSchool = null;
	public ArrayList<DMComment> mALlCommentsArray;
	private ViewPager pagers;
	private View tabs;
	private ArrayList<DMTeacher> teachers;
	private ArrayList<DMCourse> courses;
	private CommentFunctionView commentView;
	private AllThumbnailsView thumbNails;
	private FoldableAdapter<DMCourse> courseListAdapter;
	private YxFoldableListView courseList;
	private View courseListRoot;
	private LinearLayout teachersContainer;
	public ArrayList<DMTeacher> teachersList;
	private Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_school_intro);
		customizeActionBarTitle("学校信息");

		mContext = this;
		showLoading();

		mOutScroll = (ScrollView) findViewById(R.id.scrollView);

		thumbNails = (AllThumbnailsView) mOutScroll
				.findViewById(R.id.school_detail_env_images);
		thumbNails.setLastImageTipText("更多校区\n\r环境照片");
		pagers = (ViewPager) findViewById(R.id.pagers);
		pagers.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
		pagers.setOffscreenPageLimit(2);
		tabs = findViewById(R.id.head_tabs);
		UIHelper.setText(tabs, R.id.text, "学校详情");
		courseList = (YxFoldableListView) mOutScroll
				.findViewById(R.id.course_list_detail);
		courseListRoot = mOutScroll.findViewById(R.id.course_list);
		UIHelper.setText(mOutScroll.findViewById(R.id.course_list_head),
				R.id.text, "开设课程");
		teachersContainer = (LinearLayout) mOutScroll
				.findViewById(R.id.teacher_icons_hzl);

		UIHelper.setClickListener(findViewById(R.id.root), R.id.dailer,
				mClickListener);
		UIHelper.setClickListener(findViewById(R.id.scrollView),
				R.id.school_location, mClickListener);

		tryLoadDataFromWeb();
	}

	private void showLoading() {
		findViewById(R.id.root).setVisibility(View.INVISIBLE);
		findViewById(R.id.loading).setVisibility(View.VISIBLE);
	}

	@Override
	protected void onResume() {
		super.onResume();
		// 在onResume时，重新设置内嵌控件的高度。
		// pagers的高度应该为outer的高度减去tabs的高度
		pagers.post(new Runnable() {
			@Override
			public void run() {
				int outHeight = mOutScroll.getHeight();
				int tabHeight = tabs.getHeight();
				int innerWidth = pagers.getWidth();
				pagers.getLayoutParams().width = innerWidth;
				pagers.getLayoutParams().height = outHeight - tabHeight;
				pagers.invalidate();
			}
		});
	}

	private void tryLoadDataFromWeb() {
		// 尝试加载数据
		mSchoolId = getIntent().getExtras().getString(NwUtils.KEY_ID);
		if (!UIHelper.isEmpty(mSchoolId)) {
			// loading school info.
			LoadingSchoolAsyncTask lat = new LoadingSchoolAsyncTask();
			JSONObject params = new JSONObject();
			try {
				params.put(NwUtils.KEY_ID, mSchoolId);
			} catch (JSONException e) {
				e.printStackTrace();
			}
			lat.execute(NwUtils.REQ_SCHOOL_INFO, params.toString());
			// loading course list by school id.
			params = new JSONObject();
			try {
				params.put(NwUtils.KEY_SCHOOL, mSchoolId);
			} catch (JSONException e) {
				e.printStackTrace();
			}
			LoadingCoursesArrayAsyncTask lcaat = new LoadingCoursesArrayAsyncTask();
			lcaat.execute(NwUtils.REQ_COURSE_LIST, params.toString());
			// loading teacher list by school id.
			LoadingTeachersArrayAsyncTask ltaat = new LoadingTeachersArrayAsyncTask();
			ltaat.execute(NwUtils.REQ_TEACHER_LIST, params.toString());
		}
	}

	public class ViewPagerAdapter extends FragmentStatePagerAdapter {

		public ViewPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			Fragment ret = null;
			Bundle bundle = new Bundle();
			int layoutId;
			if (position == 0) {
				layoutId = R.layout.segment_h5;
				bundle.putString(YxSegment.KEY_URL, NwUtils.URL_SCHOOL_DESC
						+ mSchoolId + NwUtils.webTail());
			} else if (position == 1) {
				layoutId = R.layout.segment_course_list;
			} else {
				layoutId = R.layout.segment_teacher_list;
			}
			YxSegment fragment = YxSegment.getSegment(layoutId, bundle);
			return fragment;
		}

		@Override
		public int getCount() {
			return 1;
		}
	}

	private void fillAchivementAdapterData(YxListAdapter1 YxListAdapter1) {
		ArrayList<Integer> itemTypes = new ArrayList<Integer>();
		ArrayList<Object> data = new ArrayList<Object>();
		for (int i = 0; i < 3; i++) {
			itemTypes.add(YxDetailedInfoView1.TYPE_TEXT);
			itemTypes.add(YxDetailedInfoView1.TYPE_IMG);
			data.add(new Object());
			data.add(new Object());
		}
		YxListAdapter1.setData(itemTypes, data);
	}

	private DMAllComments getComments() {
		JSONObject params = new JSONObject();
		try {
			params.put(
					"type",
					""
							+ DetailedCommentActivity
									.convertType(Yx.TYPE_ITEM_SCHOOL));
			params.put("id", mSchoolId);
			// mAdapter 长度比 mAllComments 大一
			params.put("startIndex", 0);
			params.put("count", 1);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return DetailedCommentActivity
				.loadAllCommentsListByParams(params, this);
	}

	class LoadingSchoolAsyncTask extends AsyncTask<String, Integer, DMSchool> {

		private DMAllComments mAllCommentsObject;

		@Override
		protected DMSchool doInBackground(String... arg0) {

			try {
				String url = arg0[0];
				JSONObject jo = null;
				if (!UIHelper.isEmpty(arg0[1])) {
					jo = new JSONObject(arg0[1]);
				}
				DMSchool school = (DMSchool) NwUtils.requestDataInfo(url, jo,
						SchoolIntroductionActivity.this);
				mAllCommentsObject = getComments();
				mALlCommentsArray = mAllCommentsObject.getAllComments();
				return school;
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (JSONException e) {
				e.printStackTrace();
			}

			return null;
		}

		@Override
		protected void onPostExecute(DMSchool result) {
			super.onPostExecute(result);

			mCurSchool = result;
			if (mCurSchool == null) {
				UIHelper.showTips(mOutScroll, R.string.check_nw_and_try);
				finish();
				return;
			}

			// fill UI.
			UIHelper.setText(findViewById(R.id.scrollView), R.id.school_name,
					result.getFullSchoolName());
			UIHelper.setText(findViewById(R.id.scrollView),
					R.id.school_location, result.getAddress());
			UIHelper.asyncLoadImage(
					(ImageView) findViewById(R.id.school_image),
					result.getSchoolImage(), R.drawable.default_banner);
			// customize course info and achievement.
			RichTextHelper rh = new RichTextHelper();
			rh.parseHtmlString(result.getDescription());
			ArrayList<Object> datas = rh.getData();
			ArrayList<Integer> types = rh.getItemTypes();
			// mAchivementAdapter.setData(types, datas);

			commentView = (CommentFunctionView) findViewById(R.id.comment_function);
			if (mALlCommentsArray != null
					&& mAllCommentsObject.getTotalNum() > 0) {
				commentView.init(mALlCommentsArray.get(0));
				commentView.setNum(mAllCommentsObject.getTotalNum());
			} else if (mAllCommentsObject != null) {
				commentView.setNum(mAllCommentsObject.getTotalNum());
				commentView.initAsNoComment();
			}

			// set comment
			DMCommentLevelAvg schoolComment = result.getSchoolCommentLevel();
			if (schoolComment != null) {
				UIHelper.setText(findViewById(R.id.scrollView),
						R.id.rating_teach, "" + schoolComment.getAvgLevel1());
				UIHelper.setText(findViewById(R.id.scrollView),
						R.id.rating_teacher, "" + schoolComment.getAvgLevel2());
				UIHelper.setText(findViewById(R.id.scrollView),
						R.id.rating_environ, "" + schoolComment.getAvgLevel3());
				UIHelper.setText(findViewById(R.id.scrollView),
						R.id.rating_travel, "" + schoolComment.getAvgLevel4());
				float totalRating = Float.valueOf(schoolComment
						.getAvgTotalLevel());
				((RatingBar) findViewById(R.id.scrollView).findViewById(
						R.id.rating_bar_1)).setRating(totalRating);
			}
			((TextView) findViewById(R.id.scrollView).findViewById(
					R.id.course_label)).setText("课程标签："
					+ result.getCoursesText());
			Utils.addSchoolOnlyLabels(
					(ViewGroup) mOutScroll.findViewById(R.id.labels_school),
					result.getAuthArray());

			// / MTA stat start
			Properties prop = StatHelper
					.getBasicProp(SchoolIntroductionActivity.this);
			prop.put(StatHelper.KEY_SCHOOL, mCurSchool.getId());
			StatService.trackCustomKVEvent(SchoolIntroductionActivity.this,
					"event_school_item_show", prop);
			// / MTA stat end

			setSchoolReady(true);
			UIHelper.resetScroll(SchoolIntroductionActivity.this,
					R.id.scrollView);
		}
	}

	class LoadingTeachersArrayAsyncTask extends
			AsyncTask<String, Integer, ArrayList<DMTeacher>> {

		@Override
		protected ArrayList<DMTeacher> doInBackground(String... arg0) {
			ArrayList<DMTeacher> teachers = new ArrayList<DMTeacher>();

			try {
				String url = arg0[0];
				JSONObject jo = null;
				if (!UIHelper.isEmpty(arg0[1])) {
					jo = new JSONObject(arg0[1]);
				}
				teachers = NwUtils.requestDataInfoList(url, jo,
						UserLoginResponse.getInstance(getApplicationContext()),
						getApplicationContext());

			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (JSONException e) {
				e.printStackTrace();
			}

			return teachers;
		}

		@Override
		protected void onPostExecute(ArrayList<DMTeacher> result) {
			super.onPostExecute(result);
			// customize teachers hzl list

			teachersList = result;

			setTeachersReady(true);
			UIHelper.resetScroll(SchoolIntroductionActivity.this,
					R.id.scrollView);

		}
	}

	class LoadingCoursesArrayAsyncTask extends
			AsyncTask<String, Integer, ArrayList<DMCourse>> {

		@Override
		protected ArrayList<DMCourse> doInBackground(String... arg0) {
			ArrayList<DMCourse> courses = new ArrayList<DMCourse>();

			try {
				String url = arg0[0];
				JSONObject jo = null;
				if (!UIHelper.isEmpty(arg0[1])) {
					jo = new JSONObject(arg0[1]);
				}
				courses = NwUtils.requestDataInfoList(url, jo,
						UserLoginResponse.getInstance(getApplicationContext()),
						getApplicationContext());

			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (JSONException e) {
				e.printStackTrace();
			}

			return courses;
		}

		@Override
		protected void onPostExecute(ArrayList<DMCourse> result) {
			super.onPostExecute(result);

			courseListAdapter = courseList.new FoldableAdapter<DMCourse>();
			courseList.setAdapter(courseListAdapter);
			courseListAdapter.setData(result);
			setCoursesReady(true);
			
			if (result == null || result.size() == 0) {
				mOutScroll.findViewById(R.id.course_list).setVisibility(View.GONE);
			}
			UIHelper.resetScroll(SchoolIntroductionActivity.this,
					R.id.scrollView);
			//
		}
	}

	private void setSchoolReady(boolean schoolReady) {
		mSchoolReady = schoolReady;
		didWhenLoadingDone();
	}

	// called when load DMSchool done.
	private void fillDetailInfo(DMSchool result) {

		if (result == null || result.getSchoolBrand() == null) {
			findViewById(R.id.school_detail_brand).setVisibility(View.GONE);
		} else {
			SchoolDetailBrandDTS item = result.getSchoolBrand();
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.title), R.id.text, "品牌影响力");
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_1), R.id.key, "品牌历史");
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_2), R.id.key, "分校人数");
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_3), R.id.key, "累计学员");
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_4), R.id.key, "获奖情况");
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_1), R.id.value, item
					.getBrandHistory());
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_2), R.id.value, item
					.getBrandSchoolCount());
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_3), R.id.value, item
					.getBrandStudentCount());
			UIHelper.setText(findViewById(R.id.school_detail_brand)
					.findViewById(R.id.item_4), R.id.value, item
					.getBrandAward());
		}

		// 学校环境（包括可能的图片）
		if (result == null
				|| (result.getSchoolEnviroment() == null && UIHelper
						.isEmpty(result.getImageTurn()))) {
			findViewById(R.id.school_detail_env).setVisibility(View.GONE);
		} else {
			if (result.getSchoolEnviroment() != null) {
				customizeDetailSchoolEnv(result);
			} else {
				
				findViewById(R.id.school_detail_env).findViewById(
						R.id.detail_school_env).setVisibility(View.GONE);
			}

			if (!UIHelper.isEmpty(result.getImageTurn())) {
				UIHelper.setText(
						findViewById(R.id.school_detail_env).findViewById(R.id.title),
						R.id.text, "校区环境");
				thumbNails.setData(result.getImageTurn());
			} else {
				findViewById(R.id.school_detail_env).findViewById(
						R.id.school_detail_env_images).setVisibility(View.GONE);
			}
		}

		if (result == null
				|| (result.getSchoolTeacher() == null && (teachersList == null || teachersList
						.size() == 0))) {
			findViewById(R.id.school_detail_teacher).setVisibility(View.GONE);
		} else {
			if (result.getSchoolTeacher() != null) {
				customizeTeacherInfo(result);
			} else {
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.detail_teacher_info).setVisibility(View.GONE);
			}

			if (teachersList == null || teachersList.size() == 0) {
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.teacher_icons_hzl).setVisibility(View.GONE);
			} else {
				// 老师列表信息
				UIHelper.setText(
						findViewById(R.id.school_detail_teacher).findViewById(
								R.id.title), R.id.text, "师资力量");
				initTeachersInfo(teachersList);
			}
		}

		if (result == null || result.getSchoolService() == null) {
			findViewById(R.id.school_detail_service).setVisibility(View.GONE);
		} else {
			SchoolDetailServiceDTS item = result.getSchoolService();
			UIHelper.setText(findViewById(R.id.school_detail_service)
					.findViewById(R.id.title), R.id.text, "服务特色");
			// ，替换为空格
			String str = item.getServiceDetail();
			if (!UIHelper.isEmpty(str)) {
				String[] strs = str.split(",");
				str = "";
				for (String itemStr : strs) {
					str += (itemStr + " ");
				}
			}
			UIHelper.setText(findViewById(R.id.school_detail_service),
					R.id.detail, str);
		}
	}

	private void customizeTeacherInfo(DMSchool result) {
		SchoolDetailTeacherDTS item = result.getSchoolTeacher();
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.title), R.id.text, "师资力量");
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_1), R.id.key, "老师数量");
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_2), R.id.key, "平均教龄");
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_3), R.id.key, "老师资历");
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_1), R.id.value, item.getTeacherCount());
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_2), R.id.value, item.getTeacherAge());
		UIHelper.setText(
				findViewById(R.id.school_detail_teacher).findViewById(
						R.id.item_3), R.id.value, item.getTeacherQualifier());
	}

	private void customizeDetailSchoolEnv(DMSchool result) {
		SchoolDetailEnvironmentDTS item = result.getSchoolEnviroment();
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.title),
				R.id.text, "校区环境");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_1),
				R.id.key, "校园面积");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_2),
				R.id.key, "场所类型");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_3),
				R.id.key, "教学设施");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_4),
				R.id.key, "卫生状况");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_5),
				R.id.key, "装修程度");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_6),
				R.id.key, "家长休息区");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_7),
				R.id.key, "茶水间");
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_1),
				R.id.value, item.getEnvArea());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_2),
				R.id.value, item.getEnvType());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_3),
				R.id.value, item.getEnvFacilities());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_4),
				R.id.value, item.getEnvHealth());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_5),
				R.id.value, item.getEnvFitment());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_6),
				R.id.value, item.getEnvParentRest());
		UIHelper.setText(
				findViewById(R.id.school_detail_env).findViewById(R.id.item_7),
				R.id.value, item.getEnvPantry());
	}

	private void setTeachersReady(boolean teachersReady) {
		mTeacherReady = teachersReady;
		didWhenLoadingDone();
	}

	private void setCoursesReady(boolean coursesReady) {
		mCoursesReady = coursesReady;
		didWhenLoadingDone();
	}

	private void didWhenLoadingDone() {
		if (mSchoolReady && mTeacherReady && mCoursesReady) {
			// / 添加17维度属性和轮播图
			fillDetailInfo(mCurSchool);

			mOutScroll.post(new Runnable() {
				@Override
				public void run() {
					findViewById(R.id.root).setVisibility(View.VISIBLE);
					findViewById(R.id.loading).setVisibility(View.INVISIBLE);
				}
			});
		}

	}

	private View.OnClickListener mClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View arg0) {
			switch (arg0.getId()) {
			case R.id.dailer:
				Utils.dialPhoneNumber(SchoolIntroductionActivity.this,
						mCurSchool);
				break;
			case R.id.school_location:
				StatHelper.addKVEvent(mContext, "event_school_map_view",
						StatHelper.KEY_SCHOOL, mSchoolId);
				Utils.showLocationInMap(SchoolIntroductionActivity.this,
						mCurSchool.getSchoolGps(), mCurSchool.getAddress(),
						mCurSchool.getFullSchoolName());
				break;
			default:
				mBaseClickListener.onClick(arg0);
				break;
			}

		}
	};
	private String mSchoolId;
	private ScrollView mOutScroll;

	public String getCurSchoolId() {
		return mSchoolId;
	}

	public void setTeachersDataChangeNotifier(Observee dataChangeNotifier) {
		teachersDataChangeNotifier = dataChangeNotifier;
	}

	public void setCoursesDataChangeNotifier(Observee dataChangeNotifier) {
		coursesDataChangeNotifier = dataChangeNotifier;
	}

	public ArrayList<DMTeacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(ArrayList<DMTeacher> teachers) {
		this.teachers = teachers;
	}

	public ArrayList<DMCourse> getCourses() {
		return courses;
	}

	public void setCourses(ArrayList<DMCourse> courses) {
		this.courses = courses;
	}

	private Observee teachersDataChangeNotifier = null;
	private Observee coursesDataChangeNotifier = null;

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		super.onActivityResult(arg0, arg1, arg2);
		switch (arg0) {
		case REQ_CODE_LOGIN_FOR_ADD_COMMENT:
			if (arg1 == RESULT_OK) {
				commentView.addingComment();
			}
			break;
		}
	}

	/**
	 * Add a comment
	 * 
	 * @param view
	 */
	public void toAddingComment(View view) {
		commentView.onClick(commentView.findViewById(R.id.add_comment));
	}

	/**
	 * Report a error
	 * 
	 * @param view
	 */
	public void toReportError(View view) {
		ReportErrorDialogHelper helper = new ReportErrorDialogHelper(this);

		// 上面接口中的id type 对应类型1课程,2活动,3学校,4老师
		helper.show(3, mSchoolId);
	}

	private void initTeachersInfo(ArrayList<DMTeacher> result) {
		YxTearchersHSVHelper helper = new YxTearchersHSVHelper(
				SchoolIntroductionActivity.this);
		teachersContainer.addView(helper.getView());
		HsvAdapter helpAdapter = helper.new HsvAdapter(result);
		helper.setAdapter(helpAdapter);
	}

}
